package com.ourteam.workspace.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.workspace.dao.WorkspaceMemberDAOQueryBean;
import com.ourteam.workspace.domain.WorkspaceMemberBean;

public class WorkspaceMemberSearchModel extends AbstractSearchModel<WorkspaceMemberDAOQueryBean> {

	private long workspaceId;

	private String scmAccount;

	public long getWorkspaceId() {
		return workspaceId;
	}

	public void setWorkspaceId(long workspaceId) {
		this.workspaceId = workspaceId;
	}

	public String getScmAccount() {
		return scmAccount;
	}

	public void setScmAccount(String scmAccount) {
		this.scmAccount = scmAccount;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return WorkspaceMemberBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(WorkspaceMemberDAOQueryBean queryBean) throws Exception {
		WorkspaceMemberDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.workspaceId != 0) {
			criteria.andWorkspaceIdEqualTo(workspaceId);
		}

		if (StringUtils.isNotBlank(scmAccount)) {
			criteria.andScmAccountEqualTo(scmAccount);
		}
	}

}
